#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=5e5+5;
int n,num,nx,C,b[N*2],bx[N*2],ct[N*2];
ll w[N],val[N*2];
vector<int>a[N];
int main() {
    freopen("list.in","r",stdin);
    freopen("list.out","w",stdout);
    ios::sync_with_stdio(0),cin.tie(0);
    cin>>n,bx[nx=1]=1;
    vector<array<int,3>>op;
    for(int i=1,k;i<=n;i++) {
        cin>>k,a[i]=vector<int>(k);
        for(int j=0;j<k;j++)cin>>a[i][j],b[++num]=a[i][j];
        for(int j=1;j<k;j++)op.push_back({a[i][j]-a[i][j-1]+1,i,j}),bx[++nx]=a[i][j]-a[i][j-1]+1;
    }
    cin>>C;
    for(int i=1;i<=n;i++)cin>>w[i],w[i]*=i;
    sort(b+1,b+num+1),num=unique(b+1,b+num+1)-b-1;
    sort(bx+1,bx+nx+1),nx=unique(bx+1,bx+nx+1)-bx-1;
    sort(op.begin(),op.end());
    for(int i=1;i<=n;i++)for(int&j:a[i])j=lower_bound(b+1,b+num+1,j)-b,ct[j]++;
    ll now=0,Mn=4e18;int cur=0;
    for(int i=1;i<=num;i++)now+=w[ct[i]],cur+=ct[i];
    auto it=op.begin();
    for(int i=1;i<=nx;i++) {
        int x=bx[i];
        while(it!=op.end()&&it->at(0)<=x) {
            assert(it->at(0)==x);
            int p=it->at(1),q=it->at(2),pos=a[p][q];
            now+=w[ct[pos]-1]-w[ct[pos]]+1ll*(x-1)*C;
            ct[pos]--,cur--,it++;
        }
        val[i]=now+1ll*cur*x*C,Mn=min(Mn,val[i]);
    }
    vector<int>as;
    for(int i=1;i<=nx;i++)if(val[i]==Mn)as.push_back(bx[i]);
    cout<<Mn<<' '<<as.size()<<'\n';
    for(int i:as)cout<<i<<' ';
    return 0;
}